package com.jiang.smartcommunity.ui.activity;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.jiang.smartcommunity.MainActivity;
import com.jiang.smartcommunity.R;
import com.jiang.smartcommunity.tool.MyAdapter;

import java.util.Arrays;
import java.util.List;


public class S1Activity extends BaseActivity implements View.OnClickListener {

    private Button button;
    private RecyclerView rv;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_s1);
        initView();
        setTitle("物业服务");

    }

    private void initView() {
        button = (Button) findViewById(R.id.button);
        rv = (RecyclerView) findViewById(R.id.rv);
        rv.setLayoutManager(new LinearLayoutManager(getThis()));
        button.setOnClickListener(this);
        List<MainActivity.NotifyBean> notifyBeans = Arrays.asList(
                new MainActivity.NotifyBean("物业服务中心", "020-432425", R.drawable.ic_baseline_location_city_24),
                new MainActivity.NotifyBean("停车位服务中心", "34234255", R.drawable.ic_baseline_local_parking_24),
                new MainActivity.NotifyBean("24小时值班热线", "6787989", R.drawable.ic_round_call_24),
                new MainActivity.NotifyBean("报修电话", "12342432", R.drawable.ic_baseline_build_24),
                new MainActivity.NotifyBean("便民服务", "1231341", R.drawable.ic_baseline_emoji_emotions_24));
        rv.setAdapter(new MyAdapter<MainActivity.NotifyBean>(getThis(), R.layout.item_call, notifyBeans) {
            private ImageView imageView6;
            private TextView textView9;
            private TextView tvCall;
            private TextView textView11;

            @Override
            public void init(View root, int position) {
                imageView6 = (ImageView) root.findViewById(R.id.imageView6);
                textView9 = (TextView) root.findViewById(R.id.textView9);
                tvCall = (TextView) root.findViewById(R.id.tv_call);
                textView11 = (TextView) root.findViewById(R.id.textView11);

                MainActivity.NotifyBean item = getItem(position);
                imageView6.setImageResource(item.res);
                textView11.setText(item.c);
                textView9.setText(item.t);
                root.setOnClickListener(v -> {
                    startActivity(new Intent(Intent.ACTION_DIAL).setData(Uri.parse("tel:" + item.c)));
                });
            }
        });
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.button:
                startActivity(new Intent(getThis(), S1DActivity.class));
                break;
        }
    }

}